//
//  RootViewController.m
//  UI8_Contact_Arr
//
//  Created by dllo on 15/11/18.
//  Copyright (c) 2015年 dllo. All rights reserved.
//

#import "RootViewController.h"
#import "Student.h"

@interface RootViewController ()<UITableViewDataSource, UITableViewDelegate>

@property (nonatomic, retain) NSMutableArray *stuArr;

@end

@implementation RootViewController

- (void)dealloc
{
    [_stuArr release];
    [super dealloc];
}

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.view.backgroundColor = [UIColor whiteColor];
    
//    Student *stu1 = [[Student alloc] initWithName:@"WN" Phone:@"13311111111"];
//    Student *stu2 = [[Student alloc] initWithName:@"WBN" Phone:@"13311112222"];
//    Student *stu3 = [[Student alloc] initWithName:@"ZY" Phone:@"13311113333"];
//    Student *stu4 = [[Student alloc] initWithName:@"GS" Phone:@"13311114444"];
//    
//    
//    self.stuArr = [NSMutableArray arrayWithObjects:stu1, stu2, stu3, stu4, nil];
//    
//    [stu1 release];
//    [stu2 release];
//    [stu3 release];
//    [stu4 release];
    
    
    
    NSString *filePath = [[NSBundle mainBundle] pathForResource:@"StudentInfo" ofType:@"plist"];
    NSDictionary *dic = [NSDictionary dictionaryWithContentsOfFile:filePath];
    
    NSArray *arr = [dic objectForKey:@"stuArr"];
    
    self.stuArr = [NSMutableArray array];
    
    for (NSDictionary *tempDic in arr) {
        
        // 获取到文件中学生信息并存到学生对象中
        Student *stu = [[Student alloc] init];
        stu.name = [tempDic objectForKey:@"name"];
        stu.phone = [tempDic objectForKey:@"phone"];
        // 将学生对象添加到学生数组中
        [self.stuArr addObject:stu];
        [stu release];
    }
    
    
    UITableView *tableV = [[UITableView alloc] initWithFrame:self.view.frame style:UITableViewStylePlain];
    tableV.delegate = self;
    tableV.dataSource = self;
    [self.view addSubview:tableV];
    [tableV release];
    
    
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return self.stuArr.count;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *cellStr = @"cell";
    
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellStr];
    if (nil == cell) {
        cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:cellStr] autorelease];
    }
    
    cell.textLabel.text = [[self.stuArr objectAtIndex:indexPath.row] name];
    cell.detailTextLabel.text = [[self.stuArr objectAtIndex:indexPath.row] phone];
    
    return cell;
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
